import { createRouter, createWebHashHistory, RouteRecordRaw } from "vue-router";

export const Layout = () => import("@/layout/index.vue");

// 静态路由
export const constantRoutes: RouteRecordRaw[] = [
  {
    path: "/redirect",
    component: Layout,
    meta: { hidden: true },
    children: [
      {
        path: "/redirect/:path(.*)",
        component: () => import("@/views/redirect/index.vue"),
      },
    ],
  },

  {
    path: "/login",
    component: () => import("@/views/login/index.vue"),
    meta: { hidden: true },
  },
  {
    path: "/401",
    component: () => import("@/views/error-page/401.vue"),
    meta: { hidden: true },
  },
  {
    path: "/404",
    component: () => import("@/views/error-page/404.vue"),
    meta: { hidden: true },
  },
  // {
  //   path: "/",
  //   name: "/",
  //   component: Layout,
  //   redirect: "/meeetingMessage",
  // }
  {
    path: "/",
    name: "/",
    component: Layout,
    redirect: "/teacherInfo",
    meta: { title: "用户信息", icon: "user" },
    children: [
      {
        path: "/teacherInfo",
        component: () => import("@/views/userinfo/TeacherInfo.vue"),
        meta: {
          title: "导师信息",
          icon: "teacher",
          hidden: false,
          keepAlive: true,
        },
      },
      {
        path: "/studentInfo",
        component: () => import("@/views/userinfo/StudentInfo.vue"),
        meta: {
          title: "学生信息",
          icon: "student",
          hidden: false,
          keepAlive: true,
        },
      },
      {
        path: "/managerInfo",
        component: () => import("@/views/userinfo/ManagerInfo.vue"),
        meta: {
          title: "管理员信息",
          icon: "role",
          hidden: false,
          keepAlive: true,
        },
      },
    ],
  },
  {
    path: "/forthsix",
    redirect: "/forthsix/composition/word",
    component: Layout,
    meta: { title: "四六级专区", icon: "role" },
    children: [
      {
        path: "composition",
        redirect: "/forthsix/composition/word/evaluate/student/teacher",
        component: () => import("@/views/forthsix/composition/index.vue"),
        name: "作文模块",
        meta: {
          title: "作文模块",
          hidden: false,
          icon: "orders",
          keepAlive: true,
        },
        children: [
          {
            path: "evaluate",
            component: () =>
              import("@/views/forthsix/composition/evaluate.vue"),
            name: "作文评测大师",
            meta: {
              title: "作文评测大师",
              hidden: false,
              icon: "orders",
              keepAlive: true,
            },
          },
          {
            path: "student",
            component: () => import("@/views/forthsix/composition/student.vue"),
            name: "学生模块",
            meta: {
              title: "学生模块",
              hidden: false,
              icon: "orders",
              keepAlive: true,
            },
          },
          {
            path: "teacher",
            redirect:
              "/forthsix/composition/word/student/teacher/uploadComposition",
            component: () =>
              import("@/views/forthsix/composition/teacher/index.vue"),
            name: "老师模块",
            meta: {
              title: "老师模块",
              hidden: false,
              icon: "activity-massage",
              keepAlive: true,
            },
            children: [
              {
                path: "uploadComposition",
                component: () =>
                  import(
                    "@/views/forthsix/composition/teacher/uploadComposition.vue"
                  ),
                name: "上传作文",
                meta: {
                  title: "上传作文",
                  hidden: false,
                  icon: "orders",
                  keepAlive: true,
                },
              },
              {
                path: "score",
                component: () =>
                  import("@/views/forthsix/composition/teacher/score.vue"),
                name: "学生分数",
                meta: {
                  title: "学生分数",
                  hidden: false,
                  icon: "orders",
                  keepAlive: true,
                },
              },
            ],
          },
        ],
      },
      {
        path: "word",
        component: () => import("@/views/forthsix/word/index.vue"),
        name: "每日单词",
        meta: {
          title: "每日单词",
          hidden: false,
          icon: "orders",
          keepAlive: true,
        },
      },
    ],
  },
  // {
  //   path: "/questionBank",
  //   redirect: "/bank",
  //   component: Layout,
  //   meta: { title: "题库", icon: "client" },
  //   children: [
  //     {
  //       path: "bank",
  //       component: () => import("@/views/questionBank/children/bank.vue"),
  //       name: "题库",
  //       meta: {
  //         title: "题库",
  //         hidden: false,
  //         icon: "activity2",
  //         keepAlive: true,
  //       },
  //     },
  //     {
  //       path: "questionAnswering",
  //       component: () =>
  //         import("@/views/questionBank/children/questionAnswering.vue"),
  //       name: "智能问答",
  //       meta: {
  //         title: "智能问答",
  //         hidden: false,
  //         icon: "eye-open",
  //         keepAlive: true,
  //       },
  //     },
  //   ],
  // },

  {
    path: "/explainSystem",
    component: Layout,
    redirect: "/explainSystem",
    meta: { icon: "feedback" },
    children: [
      {
        path: "/explainSystem",
        component: () => import("@/views/explainSystem/index.vue"),
        meta: {
          title: "智码精灵",
          icon: "feedback",
          hidden: false,
          keepAlive: true,
          roles: ["student"],
        },
      },
    ],
  },

  {
    path: "/exam",
    component: Layout,
    redirect: "/exam/repo",
    name: "Manage",
    meta: {
      title: "考试管理",
      icon: "client",
      roles: ["sa", "teacher"],
    },
    children: [
      {
        path: "/repo",
        component: () => import("@/views/qu/repo/index.vue"),
        name: "ListRepo",
        meta: { title: "题库管理", noCache: true, icon: "client" },
      },

      // {
      //   path: "repo/add",
      //   component: () => import("@/views/qu/repo/form.vue"),
      //   name: "AddRepo",
      //   meta: { title: "添加题库", noCache: true, activeMenu: "/exam/repo" },
      //   hidden: true,
      // },

      // {
      //   path: "repo/update/:id",
      //   component: () => import("@/views/qu/repo/form.vue"),
      //   name: "UpdateRepo",
      //   meta: { title: "题库详情", noCache: true, activeMenu: "/exam/repo" },
      //   hidden: true,
      // },

      {
        path: "qu",
        component: () => import("@/views/qu/qu/index.vue"),
        name: "ListQu",
        meta: { title: "试题管理", noCache: true, icon: "client" },
      },

      // {
      //   path: "qu/add",
      //   component: () => import("@/views/qu/qu/form.vue"),
      //   name: "AddQu",
      //   meta: { title: "添加试题", noCache: true, activeMenu: "/exam/qu" },
      //   hidden: true,
      // },

      // {
      //   path: "qu/update/:id",
      //   component: () => import("@/views/qu/qu/form.vue"),
      //   name: "UpdateQu",
      //   meta: { title: "修改试题", noCache: true, activeMenu: "/exam/qu" },
      //   hidden: true,
      // },

      {
        path: "exam",
        component: () => import("@/views/exam/exam/index.vue"),
        name: "ListExam",
        meta: { title: "考试管理", noCache: true, icon: "client" },
      },

      // {
      //   path: "exam/add",
      //   component: () => import("@/views/exam/exam/form.vue"),
      //   name: "AddExam",
      //   meta: { title: "添加考试", noCache: true, activeMenu: "/exam/exam" },
      //   hidden: true,
      // },

      // {
      //   path: "exam/update/:id",
      //   component: () => import("@/views/exam/exam/form.vue"),
      //   name: "UpdateExam",
      //   meta: { title: "修改考试", noCache: true, activeMenu: "/exam/exam" },
      //   hidden: true,
      // },
    ],
  },

  {
    path: "/my",
    component: Layout,
    redirect: "/my/exam",
    name: "Online",
    meta: {
      title: "在线考试",
      icon: "client",
      roles: ["student", "sa"],
    },
    children: [
      {
        path: "exam",
        component: () => import("@/views/paper/exam/list.vue"),
        name: "ExamOnline",
        meta: { title: "在线考试", noCache: true, icon: "client" },
      },

      // {
      //   path: "exam/prepare/:examId",
      //   component: () => import("@/views/paper/exam/preview.vue"),
      //   name: "PreExam",
      //   meta: { title: "准备考试", noCache: true, activeMenu: "/my/exam" },
      //   hidden: true,
      // },

      // {
      //   path: "exam/result/:id",
      //   component: () => import("@/views/paper/exam/result.vue"),
      //   name: "ShowExam",
      //   meta: { title: "考试结果", noCache: true, activeMenu: "/online/exam" },
      //   hidden: true,
      // },

      {
        path: "exam/records",
        component: () => import("@/views/user/exam/my.vue"),
        name: "ListMyExam",
        meta: { title: "我的成绩", noCache: true, icon: "client" },
      },

      // {
      //   path: "book/list/:examId",
      //   component: () => import("@/views/user/book/index.vue"),
      //   name: "BookList",
      //   meta: {
      //     title: "考试错题",
      //     noCache: true,
      //     activeMenu: "/my/exam/records",
      //   },
      //   hidden: true,
      // },

      // {
      //   path: "book/training/:examId",
      //   component: () => import("@/views/user/book/train.vue"),
      //   name: "BookTraining",
      //   meta: {
      //     title: "错题训练",
      //     noCache: true,
      //     activeMenu: "/my/exam/records",
      //   },
      //   hidden: true,
      // },
    ],
  },
  {
    path: "/pathPlan",
    component: Layout,
    redirect: "/study",
    meta: { title: "路线规划", icon: "consult" },
    children: [
      {
        path: "/study",
        component: () => import("@/views/pathPlan/children/study.vue"),
        name: "学习科目",
        meta: {
          title: "学习科目",
          icon: "publish",
          hidden: false,
          keepAlive: true,
        },
      },
      {
        path: "/ai",
        component: () => import("@/views/pathPlan/children/ai.vue"),
        name: "智能导师",
        meta: {
          title: "智能导师",
          icon: "customer-service",
          hidden: false,
          keepAlive: true,
        },
      },
    ],
  },
  {
    path: "/suggestion",
    redirect: "/submit",
    component: Layout,
    meta: { title: "意见反馈", icon: "link" },
    children: [
      {
        path: "/submit",
        component: () => import("@/views/suggestion/children/submit.vue"),
        name: "提交反馈",
        meta: {
          title: "提交反馈",
          hidden: false,
          icon: "peoples",
          keepAlive: true,
        },
      },
      {
        path: "/checks",
        component: () => import("@/views/suggestion/children/checks.vue"),
        name: "查看反馈",
        meta: {
          title: "查看反馈",
          hidden: false,
          icon: "edit",
          keepAlive: true,
        },
      },
    ],
  },
];

/**
 * 创建路由
 */
const router = createRouter({
  history: createWebHashHistory(),
  routes: constantRoutes as RouteRecordRaw[],
  // 刷新时，滚动条位置还原
  scrollBehavior: () => ({ left: 0, top: 0 }),
});

/**
 * 重置路由
 */
export function resetRouter() {
  router.replace({ path: "/login" });
}

export default router;
